#!/usr/bin/env python3

import subprocess

def get_files():
    return subprocess.check_output(['git', 'diff-index', '--cached',
                                    '--name-only', 'HEAD']).split()
def apply_code_style():
    files = filter(lambda x: x.find(b'third_party') == -1, get_files())

    files = filter(lambda x: x.endswith(b'.c') or
                             x.endswith(b'.h') or
                             x.endswith(b'.hpp') or
                             x.endswith(b'.cpp') or
                             x.endswith(b'.cppm'),files)
    for f in files:
        print("Apply code style to: " + str(f))
        subprocess.check_output(['clang-format-20', '-i', f])
        subprocess.check_output(['git', 'add', f])

def main():
    apply_code_style()

if (__name__ == '__main__'):
    main()
